<template>
  <div class="container">
    <div class="main-content">
      <div class="bj-content">
        <div class="content">
          <div class="title-content">
            <div class="border"></div>
            <div>
              <div class="title">欢迎登录</div>
              <!-- <div class="subtitle">让摄影管理更方便</div> -->
            </div>
          </div>
          <div class="form-content">
            <el-form
              :model="form"
              :rules="rules"
              ref="ruleForm"
              label-width="auto"
            >
              <el-form-item prop="username">
                <el-input
                  v-model="form.username"
                  placeholder="请输入账户名称"
                  clearable
                  class="item-filter-width"
                ></el-input>
              </el-form-item>

              <el-form-item prop="password">
                <el-input
                  v-model="form.password"
                  placeholder="请输入账户密码"
                  clearable
                  class="item-filter-width"
                ></el-input>
              </el-form-item>
            </el-form>

            <div class="btn-content">
              <el-button type="success" class="btn" @click="login('ruleForm')"
                >立即登录</el-button
              >
              <div class="amend">
                <!-- <el-link @click="">忘记密码？</el-link> -->

                <el-link type="primary" @click="gotoRegister()"
                  >用户注册</el-link
                >
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { EnterpriseLoginService } from "@/api/enterprise";
import store from "@/store";
export default {
  name: "app-login",
  data() {
    return {
      result: "",
      form: {
        username: "",
        password: "",
      },

      rules: {
        username: [
          { required: true, message: "请输入账户名称", trigger: "blur" },
        ],

        password: [
          { required: true, message: "请输入账户密码", trigger: "blur" },
        ],
      },
    };
  },

  methods: {
    //跳转到注册
    gotoRegister() {
      this.$router.push("/register");
    },
    // 登录
    login(formName) {
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          this.result = await EnterpriseLoginService(this.form);
          console.log(this.result?.code);
          if (this.result?.code == 0) {
            this.$message({
              message: "登陆成功",
              type: "success",
              center: true,
            });
            console.log(this.result.data);
            store.commit("setToken", this.result.data);
            this.$router.push("/");
          } else {
            this.$message({
              message: this.result?.message,
              type: "error",
              center: true,
            });
          }
        } else {
          return false;
        }
      });
    },
  },
  created() {
    // console.log(store.state.token);
    // store.commit("removeToken");
    // console.log(store.state.token);
    // store.commit("setToken", 2);
    // console.log(store.state.token);
  },
};
</script>

<style lang="scss" scoped>
.container {
  width: 100vw;
  height: 100vh;
  background: #fff url("@/assets/images/980.jpg");
  background-attachment: fixed;
  background-size: cover;
  position: relative;
  overflow: hidden;
}

.main-content {
  width: 490px;
  height: 550px;
  background-color: #fff;
  position: absolute;
  top: 46%;
  right: 8%;
  transform: translateY(-50%);
  z-index: 1;
  border-radius: 15px;
  box-shadow: 0px 2px 10px 2px rgba(0, 0, 0, 0.25);
  overflow: hidden;

  .bj-content {
    width: 100%;
    height: 100%;
    position: relative;

    &::after {
      width: 100%;
      height: 125px;
      content: "";
      position: absolute;
      left: 0;
      top: 0;
      z-index: 1;
    }

    &::before {
      width: 430px;
      height: 70px;
      content: "";
      position: absolute;
      right: 0;
      bottom: 0;
      z-index: 1;
    }

    .content {
      position: absolute;
      left: 0;
      top: 0;
      right: 0;
      bottom: 0;
      z-index: 2;
      padding: 75px 80px;
      box-sizing: border-box;

      .title-content {
        display: flex;
        flex-direction: row;
        align-items: center;

        .border {
          width: 8px;
          height: 52px;
          background-color: #6b8d37;
          margin-right: 15px;
        }

        .title {
          font-size: 24px;
          font-weight: bold;
          color: #6b8d37;
        }

        .subtitle {
          font-size: 16px;
          line-height: 26px;
          color: #888387;
        }
      }

      .form-content {
        margin-top: 40px;
      }
    }
  }
}

.btn-content {
  margin-top: 80px;

  .btn {
    width: 100%;
    display: block;
  }

  .amend {
    margin-top: 20px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
  }
}

::v-deep .el-button--success {
  background-color: #6c8e38;
  border-color: #6c8e38;
  padding: 17px 20px;
}

.item-filter-width {
  width: 100%;
}

::v-deep .el-form-item {
  margin-bottom: 25px;
}

::v-deep .el-input__inner {
  height: 50px;
}
</style>
